home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / compuserve-file-archive / 22 Graphics & Utilities / HOPC.SRC < prev    next >
Encoding:
Text File  |  2019-04-13  |  4.1 KB  |  156 lines

  1.  /* This is the HOPALONG program described in A. K. Dewdney's COMPUTER       */
  2.  /* RECREATION column in Scientific American. This and many other intriguing */ 
  3.  /* can be found in "The Armchair Universe", published by W. H. Freeman and  */
  4.  /* Company, New York, 1988.                                                 */
  5.  /*                                                                          */
  6.  /* Coded by James Britt, May, 1989.                                         */
  7.  
  8.  #include"stdio.h"
  9.  #include"graphic.h"
  10.  #include"math.h"
  11.  #define LTGREEN   '\231'
  12.  #define    STOP   '\003'
  13.  #define  LTBLUE   '\232'
  14.  #define     RED   '\034'
  15.  /*  #define       X     'X'       */
  16.  
  17.  
  18.  
  19.  
  20.  main()
  21.  
  22.  char   cyc;
  23.  float  a, b, c;
  24.  int i, num, t, j, k, w, s;
  25.  float  xx, yy, com, x, y;
  26.  int    c1, c2, c3, temp;
  27.  
  28.  printf("%c%c%c", CLR, HOME, LTBLUE );
  29.  printf("\n\n          %cH O P A L O N G",RED);
  30.  printf("\n\n%cThis program is from A. K. Dewdney's ",LTBLUE);
  31.  printf("\n%cComputer Recreations %ccolumn
  32. in\n%cScientific",LTGREEN,LTBLUE,RED);
  33.  printf(" American. %c",LTBLUE);
  34.  printf("\n\nThe %cSTOP %ckey interrupts the \nitteration cycle",RED,LTBLUE);
  35.  printf("to allow you\nto modify the parameters.");
  36.  printf("\n\n\n%cUse STOP/RESTORE to quit.",RED);
  37.  printf("\n\n           %c(Hit any key)",LTGREEN);
  38.  
  39.  getchar();
  40.  
  41.  printf("%c%c%c", CLR, HOME, LTBLUE );
  42.  printf("\n\n The program plots the equation ");
  43.  printf("\n    xx=y-sign(x)*[abs(b*x-c)]**0.5 ");
  44.  printf("\n    yy=a-x ");
  45.  printf("\n    x=xx   ");
  46.  printf("\n    y=yy   ");
  47.  printf("\n\nSome suggested values: ");
  48.  printf("\n   a         b        c  ");
  49.  printf("\n  -3.14      0.3      0.3 ");
  50.  printf("\n   0.4       1        0   ");
  51.  printf("\n  23        -0.4    100   ");
  52.  printf("\n\nThe X, Y offsets allow you to shift");
  53.  printf("\nthe screen location of the plotted");
  54.  printf("\npoints. The distortion factor expands");
  55.  printf("\nor contracts the plotted image.");
  56.  printf("\n\n%c           (Hit any key)",RED);
  57.  
  58.  getchar();
  59.  
  60.  printf("%c%c%c", CLR, HOME, LTBLUE );
  61.  printf("\n\n\nColor cycle changes the color of");
  62.  printf("\neach dot, cycling through red, green");
  63.  printf("\nand blue. It makes for a very pretty");
  64.  printf("\neffect.");
  65.  printf("\n\n\n%cWell, have fun. And check out the book",LTGREEN);
  66.  printf("\n%cThe Armchair Universe, %cby A.K. Dewdney.",RED, LTGREEN);
  67.  printf("\n\n               %cJames Britt, May 1989",LTBLUE);
  68.    printf("\n\n         %c(Hit any key)",RED);
  69.  
  70.  getchar();
  71.  
  72.  while()      /*   endless main body loop    */
  73.  
  74.  printf("%c%c%c", CLR, HOME, RED);
  75.  printf("\n  Enter a, b, c: ");
  76.  scanf("%f%f%f", &a, &b, &c);
  77.  printf("\n  Enter x and y offsets:  ");
  78.  scanf("%d%d", &j, &k);
  79.  /* offsets the plotted points  */
  80.  
  81.  printf("\n  Enter distortion factor_\b");
  82.  scanf("%f", &com);
  83.  /* con is multiplied with x and y to expand or contract the plotted image */
  84.  
  85.  printf("\n\n  Color cycle? (y/n):  ");
  86.  scanf("%c",&cyc);
  87.  
  88.  
  89.  graphic(); /*  allocates grafx memory   */
  90.  backgr(14,0); /* sets boarder and background colors  */
  91.  graphon();clrmap(0);
  92.  c1=red; c2=blue; c3=green;
  93.  colors(c1, c2, c3 ); /* sets colors for classes 1, 2, and 3  */
  94.  
  95.  x=0; y=0;
  96.  i=1;
  97.  
  98.  
  99.  while () 
  100.  
  101.     w=(int)(x*com); s=(int)(y*com);
  102.     dot(j+w, k+s);
  103.     setcol((i%3)+1);
  104.  
  105.     xx=y-(sgn(x)*sqrt(abs(b*x-c)));
  106.  
  107.     yy=a-x;
  108.     x=xx; y=yy;
  109.  
  110.     i++;
  111.  
  112.  
  113.  
  114.  if (getc(STDIO)==STOP)
  115.     graphoff();
  116.     printf("%c%c%c\n\n\n", CLR, HOME, LTBLUE );
  117.  
  118.     printf("\nA  = %3g",a);
  119.     printf("\nB  = %3g",b);
  120.     printf("\nC  = %3g",c);
  121.  
  122.     printf("\n\nEnter new A, B, C: ");
  123.     scanf("%f%f%f",&a,&b,&c);
  124.  
  125.     printf("\n\nCurrent displacement = %d, %d",j,k);
  126.     printf("\nEnter new displacement: ");
  127.     scanf("%d%d",&j,&k);
  128.     printf("\n\nCurrent distortion = %5g", com);
  129.     printf("\nEnter new distortion =  ");
  130.     scanf("%f",&com);
  131.     printf("\n\nColor cycle? (y/n): ");
  132.     scanf("%c",&cyc);
  133.  
  134.     x=0; y=0; i=1;
  135.     graphon();
  136.     clrmap(0);
  137.  
  138.       /*    end if-stop    */
  139.  
  140.  if(cyc=='y')
  141.    temp=c1; c1=c2; c2=c3; c3=temp;
  142.    colors(c1,c2,c3);
  143.    
  144.  
  145.    /* end inner while()     */
  146.  
  147.  graphoff();
  148.  
  149.  
  150.    /*  end outer while()   */
  151.  
  152.   /* end main()   */
  153.  
  154.  
  155.  
  156.